#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
map<char, char> mp;

void solve()
{
    mp['p'] = 'q';
    mp['w'] = 'w';
    mp['q'] = 'p';
    string s;
    cin >> s;
    string ans;
    for(auto & ch:s)
    {
        ans+=mp[ch];
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    cout << endl;
}
int main()
{
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
